﻿<%@ WebHandler Language="C#" Class="ColorHandler" %>

using System;
using System.Web;
using SeDuce.BLL;
using SeDuce.Model;

public class ColorHandler : IHttpHandler {

    Lazy_Yu<ColorBLL> lazyColorBLL = new Lazy_Yu<ColorBLL>(() => new ColorBLL());
    public ColorBLL LazyColorBLL
    {
        get { return this.lazyColorBLL.Value; }
    }
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        ColorData colorData = context.Request.Form["colordata"].ToString().FromJsonTo<ColorData>();

        JSONStatus status = new JSONStatus() { Status = "0" };
        if (colorData.ColorList.Count > 0)
        {
            if (!this.LazyColorBLL.UpdateColors(colorData.ColorList))
            {
                status.Status = "1";
            }
        }

        context.Response.Write(status.ToJSON());
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}